<template>
  <van-list
    v-model="loading"
    :finished="finished"
    finished-text="没有更多了"
    @load="onLoad"
  >
    <CommentItem v-for="(item, index) in list" :key="index" :comment="item" />
  </van-list>
</template>

<script>
import { getArticleComment } from '../../../api/comment'
import CommentItem from './comment-item'
export default {
  name: 'CommentList',

  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      offset: null
    };
  },
  components: {
    CommentItem
  },
  props: {
    artId: {
      type: [Number, String],
      require: true
    }
  },
  mounted() {

  },
  created() {
    this.onLoad()
  },
  methods: {
    async onLoad() {
      try {
        const { data } = await getArticleComment({
          type: 'a',
          source: this.artId,
          offset: this.offset,
          limit: 10
        })
        const { results } = data.data
        console.log(data.data);
        this.$emit('event-name', data.data);
        this.list.push(...results)
        this.loading = false
        if (results.length) {
          this.offset = data.data.last_id
        } else {
          this.finished = true
        }
      } catch (error) {

      }
    }
  }
};
</script>

<style lang="less" scoped>
</style>